<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>empty_value</title>
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
<link rel="prev" href="demangle.html" title="demangle">
<link rel="next" href="enable_if.html" title="enable_if">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="demangle.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="enable_if.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="core.empty_value"></a><a class="link" href="empty_value.html" title="empty_value">empty_value</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="empty_value.html#core.empty_value.overview">Overview</a></span></dt>
<dt><span class="section"><a href="empty_value.html#core.empty_value.examples">Examples</a></span></dt>
<dt><span class="section"><a href="empty_value.html#core.empty_value.reference">Reference</a></span></dt>
</dl></div>
<div class="simplesect">
<div class="titlepage"><div><div><h3 class="title">
<a name="idm5298"></a>Authors</h3></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
          Glen Fernandes
        </li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.empty_value.overview"></a><a class="link" href="empty_value.html#core.empty_value.overview" title="Overview">Overview</a>
</h3></div></div></div>
<p>
        The header &lt;boost/core/empty_value.hpp&gt; provides the class template
        <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">empty_value</span></code> for library authors to conveniently
        leverage the Empty Base Optimization to store objects of potentially empty
        types.
      </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.empty_value.examples"></a><a class="link" href="empty_value.html#core.empty_value.examples" title="Examples">Examples</a>
</h3></div></div></div>
<p>
        The following example shows <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">empty_value</span></code>
        used to create a type that stores a pointer, comparer, and allocator, where
        the comparer and allocator could be empty types.
      </p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Ptr</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Compare</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">storage</span>
    <span class="special">:</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Compare</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;</span>
    <span class="special">,</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Allocator</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
    <span class="identifier">storage</span><span class="special">()</span>
        <span class="special">:</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Compare</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;(</span><span class="identifier">empty_init_t</span><span class="special">())</span>
        <span class="special">,</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Allocator</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;(</span><span class="identifier">empty_init_t</span><span class="special">())</span>
        <span class="special">,</span> <span class="identifier">ptr_</span><span class="special">()</span> <span class="special">{</span> <span class="special">}</span>

    <span class="identifier">storage</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Compare</span><span class="special">&amp;</span> <span class="identifier">c</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Allocator</span><span class="special">&amp;</span> <span class="identifier">a</span><span class="special">)</span>
        <span class="special">:</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Compare</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;(</span><span class="identifier">empty_init_t</span><span class="special">(),</span> <span class="identifier">c</span><span class="special">)</span>
        <span class="special">,</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Allocator</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;(</span><span class="identifier">empty_init_t</span><span class="special">(),</span> <span class="identifier">a</span><span class="special">)</span>
        <span class="special">,</span> <span class="identifier">ptr_</span><span class="special">()</span> <span class="special">{</span> <span class="special">}</span>

    <span class="keyword">const</span> <span class="identifier">Ptr</span><span class="special">&amp;</span> <span class="identifier">pointer</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">ptr_</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="identifier">Ptr</span><span class="special">&amp;</span> <span class="identifier">pointer</span><span class="special">()</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">ptr_</span><span class="special">;</span>
    <span class="special">}</span>

    <span class="keyword">const</span> <span class="identifier">Compare</span><span class="special">&amp;</span> <span class="identifier">compare</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Compare</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;::</span><span class="identifier">get</span><span class="special">();</span>
    <span class="special">}</span>

    <span class="identifier">Compare</span><span class="special">&amp;</span> <span class="identifier">compare</span><span class="special">()</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Compare</span><span class="special">,</span> <span class="number">0</span><span class="special">&gt;::</span><span class="identifier">get</span><span class="special">();</span>
    <span class="special">}</span>

    <span class="keyword">const</span> <span class="identifier">Allocator</span><span class="special">&amp;</span> <span class="identifier">allocator</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Allocator</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;::</span><span class="identifier">get</span><span class="special">();</span>
    <span class="special">}</span>

    <span class="identifier">Allocator</span><span class="special">&amp;</span> <span class="identifier">allocator</span><span class="special">()</span> <span class="special">{</span>
        <span class="keyword">return</span> <span class="identifier">empty_value</span><span class="special">&lt;</span><span class="identifier">Allocator</span><span class="special">,</span> <span class="number">1</span><span class="special">&gt;::</span><span class="identifier">get</span><span class="special">();</span>
    <span class="special">}</span>

<span class="keyword">private</span><span class="special">:</span>
    <span class="identifier">Ptr</span> <span class="identifier">ptr_</span><span class="special">;</span>
<span class="special">};</span>
</pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="core.empty_value.reference"></a><a class="link" href="empty_value.html#core.empty_value.reference" title="Reference">Reference</a>
</h3></div></div></div>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>

<span class="keyword">struct</span> <span class="identifier">empty_init_t</span> <span class="special">{</span> <span class="special">};</span>

<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">Index</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">Empty</span> <span class="special">=</span> <span class="emphasis"><em>see below</em></span><span class="special">&gt;</span>
<span class="keyword">class</span> <span class="identifier">empty_value</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
    <span class="keyword">typedef</span> <span class="identifier">T</span> <span class="identifier">type</span><span class="special">;</span>

    <span class="identifier">empty_value</span><span class="special">()</span> <span class="special">=</span> <span class="keyword">default</span><span class="special">;</span>

    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">&gt;</span>
    <span class="identifier">empty_value</span><span class="special">(</span><span class="identifier">empty_init_t</span><span class="special">,</span> <span class="identifier">Args</span><span class="special">&amp;&amp;...</span> <span class="identifier">args</span><span class="special">);</span>

    <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span>

    <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">;</span>
<span class="special">};</span>

<span class="keyword">inline</span> <span class="keyword">constexpr</span> <span class="identifier">empty_init_t</span> <span class="identifier">empty_init</span><span class="special">{</span> <span class="special">};</span>

<span class="special">}</span> <span class="comment">/* boost */</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.empty_value.reference.template_parameters"></a><a class="link" href="empty_value.html#core.empty_value.reference.template_parameters" title="Template parameters">Template
        parameters</a>
</h4></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="identifier">T</span></code></span></dt>
<dd><p>
                The type of value to store
              </p></dd>
<dt><span class="term"><code class="computeroutput"><span class="identifier">Index</span></code></span></dt>
<dd><p>
                Optional: Specify to create a distinct base type
              </p></dd>
<dt><span class="term"><code class="computeroutput"><span class="identifier">Empty</span></code></span></dt>
<dd><p>
                Optional: Specify to force inheritance from type
              </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.empty_value.reference.member_types"></a><a class="link" href="empty_value.html#core.empty_value.reference.member_types" title="Member types">Member types</a>
</h4></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="identifier">type</span></code></span></dt>
<dd><p>
                The template parameter <code class="computeroutput"><span class="identifier">T</span></code>
              </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.empty_value.reference.constructors"></a><a class="link" href="empty_value.html#core.empty_value.reference.constructors" title="Constructors">Constructors</a>
</h4></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="identifier">empty_value</span><span class="special">()</span>
            <span class="special">=</span> <span class="keyword">default</span><span class="special">;</span></code></span></dt>
<dd><p>
                Default initialize the value
              </p></dd>
<dt><span class="term"><code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span><span class="special">...</span> <span class="identifier">Args</span><span class="special">&gt;</span>
            <span class="identifier">empty_value</span><span class="special">(</span><span class="identifier">empty_init_t</span><span class="special">,</span>
            <span class="identifier">Args</span><span class="special">&amp;&amp;...</span>
            <span class="identifier">args</span><span class="special">);</span></code></span></dt>
<dd><p>
                Initialize the value with <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">forward</span><span class="special">&lt;</span><span class="identifier">Args</span><span class="special">&gt;(</span><span class="identifier">args</span><span class="special">)...</span></code>
              </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="core.empty_value.reference.member_functions"></a><a class="link" href="empty_value.html#core.empty_value.reference.member_functions" title="Member functions">Member
        functions</a>
</h4></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
<dl class="variablelist">
<dt><span class="term"><code class="computeroutput"><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span> <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt>
<dd><p>
                Returns the value
              </p></dd>
<dt><span class="term"><code class="computeroutput"><span class="identifier">T</span><span class="special">&amp;</span>
            <span class="identifier">get</span><span class="special">()</span>
            <span class="keyword">noexcept</span><span class="special">;</span></code></span></dt>
<dd><p>
                Returns the value
              </p></dd>
</dl>
</div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="demangle.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="enable_if.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
